package com.itqf.controller;

import com.itqf.exception.LoginException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * projectName: springmvc2103
 *
 * @author: 赵伟风
 * time: 2021/7/5 15:28
 * description:
 */

@RestController
@RequestMapping("user")
public class UserController {

    /**
     * 逻辑流程
     *   1.正常流程
     *   2.异常处理流
     * @param account
     * @param password
     * @return
     */
    @GetMapping("login")
    public Object login(String account,String password){

        Map map = new HashMap();

        if(account.equalsIgnoreCase("root") && password.equalsIgnoreCase("root"))
        {
            map.put("code", 1);
        }else{
            map.put("code", 0);
        }

        return map;
    }

    @GetMapping("loginerror")
    public Object logineerror(String account,String password) throws LoginException {

        Map map = new HashMap();

        if(account.equalsIgnoreCase("root") && password.equalsIgnoreCase("root"))
        {
            map.put("code", 1);
        }else{

            throw new LoginException(account+"不正确,登录失败!");
        }

        return map;
    }


}
